package Verktoy;

import java.sql.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 * Klasse som konverterer dato mellom string og object
 * @author Gruppe1
 */
@ManagedBean(name="dato")
public class DateConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        String [] delt = value.split("-");
        return delt.length != 3 || value == null || value.equals("") ? null : Date.valueOf(value);//new Date(Integer.parseInt(delt[0].trim()), Integer.parseInt(delt[1].trim()), Integer.parseInt(delt[2].trim()));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return value.toString();
    }
    
}
